package com.soft.trading;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.soft.trading.service.AdvancedAccessibilityService;

public class MainActivity extends AppCompatActivity {

    private UIOperator uiOperator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        uiOperator = new UIOperator();

        startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS));

        Button startAutoBtn = findViewById(R.id.btn_start_auto);
        startAutoBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d("1234","11111111111111111");
                startAutomation();
            }
        });
    }

    private void startAutomation() {
        // 检查无障碍服务
//        if (!isAccessibilityServiceEnabled()) {
//            showAccessibilityGuide();
//            return;
//        }

        // 打开目标App
        openTargetApp("com.cmschina.stock");

        // 自动化操作会在无障碍服务中自动执行
    }

    private boolean isAccessibilityServiceEnabled() {
        // 检查无障碍服务是否启用
        return AdvancedAccessibilityService.getInstance() != null;
    }

    private void showAccessibilityGuide() {
        // 显示无障碍服务引导
        Log.d("1234","2222222222");
    }

    private void openTargetApp(String packageName) {
        // 打开目标App
        Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
        if (intent != null) {
            startActivity(intent);
        }
    }
}
